/**
* @Title: CharacterUtil.java
* @Package com.alex.cms.util
* @Description: (描述该文件做什么)
* @author Alex Lu
* @date 2019年9月18日 上午10:14:29
* @version V1.0
*/
package com.alex.cms.util;

import java.util.List;

import org.springframework.util.CollectionUtils;
import org.springframework.web.servlet.ModelAndView;

import com.alex.cms.domain.CmsArticle;

/**
 * @ClassName: CharacterUtil
 * @Description: 对char处理的工具类
 * @author Alex Lu
 * @date 2019年9月18日 上午10:14:29
 *
 */
public class PageUtil {
	public static ModelAndView getArticlePage(List<CmsArticle> list,Integer articleId,Integer type){

		ModelAndView mav = null;
		if (CollectionUtils.isEmpty(list)) {
			mav = new ModelAndView("redirect:/article/" + articleId);
			return mav;
		}
		if (list.size() == 1) {
			mav = new ModelAndView("redirect:/article/" + articleId);
			return mav;
		}
		for (int i = 0; i < list.size(); i++) {
			if (list.get(i).getId().intValue() == articleId.intValue()) {
				if (type == 1) {
					if (i < list.size() - 1) {
						mav = new ModelAndView("redirect:/article/" + list.get(i + 1).getId());
						return mav;
					} else if (i == list.size() - 1) {
						mav = new ModelAndView("redirect:/article/" + list.get(list.size() - 1).getId());
						return mav;
					}
				} else {
					if (i == 0) {
						mav = new ModelAndView("redirect:/article/" + list.get(0).getId());
						return mav;
					} else if (i <= list.size() - 1) {
						mav = new ModelAndView("redirect:/article/" + list.get(i - 1).getId());
						return mav;
					}
				}
			}
		}
		return mav;
	}
}
